<?php

namespace JsonLowCode;

use JsonLowCode\Support\Fluent;
use JsonLowCode\Traits\HasMake;

/**
 * 脚本包
 * "package"=>"konva",
 * "library"=>"Konva",
 * "version"=>"8.3.13",
 * "urls"=>["https://unpkg.com/konva@8.3.13/konva.min.js"],
 * "maps"=>[],
 */
class Package extends Fluent
{
    use HasMake;

    public function __construct(array|callable $args = null)
    {
        parent::__construct();
        if ($args!=null){
            if (is_array($args)){
                $this->attributes = $args;
            }
            if (is_callable($args)){
                call_user_func($args, $this);
            }
        }
    }

    /**
     * 主包名称
     * @param string $package
     * @return $this
     */
    public function package(string $package): static
    {
        $this->attributes['package'] = $package;
        return $this;
    }

    /**
     * 主包window变量对象
     * @param string $library
     * @return $this
     */
    public function library(string $library): static
    {
        $this->attributes['library'] = $library;
        return $this;
    }

    /**
     * 主包版本
     * @param string $version
     * @return $this
     */
    public function version(string $version): static
    {
        $this->attributes['version'] = $version;
        return $this;
    }

    /**
     * 引入js脚本
     * @param array $urls
     * @return $this
     */
    public function urls(array $urls): static
    {
        $this->attributes['urls'] = $urls;
        return $this;
    }

    /**
     * 引入js脚本
     * @param string $url
     * @return $this
     */
    public function url(string $url): static
    {
        $this->attributes['urls'][] = $url;
        return $this;
    }

    /**
     * 组件映射
     * @param array $maps
     * @return $this
     */
    public function maps(array $maps): static
    {
        $this->attributes['maps'] = $maps;
        return $this;
    }

    /**
     * 组件映射
     * @param $map
     * @return $this
     */
    public function map($map): static
    {
        $this->attributes['maps'][] = $map;
        return $this;
    }


}
